/**
 * @author daniele.gili@usi.ch
 * @author blancsv@usi.ch
 */
package ch.usi.inf.pf2;

import java.awt.Graphics;
import java.util.Timer;

public class And extends CommonGate implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public And(Timer a, int x, int y, int pos) {
		this.myTimer = a;
		myTimer.schedule(new ActionDelay(this), 0L, 1L);
		this.x = x - getWidth() / 2 - 10;
		this.y = y - getHeight() / 2;
		this.pos = pos;
	}

	public And(Timer a) {
		this.myTimer = a;
		myTimer.schedule(new ActionDelay(this), 200L, 200L);
		this.x = 0;
		this.y = 0;
		this.pos = 0;
	}

	public void setNewValue() {

		if (inputList.size() == 0) {
			actualValue = null;
			return;
		}

		for (int a = 0; a <= inputList.size() - 1; a++) {
			if (inputList.get(a).getValue(actualIndex) == null) {
				actualValue = null;
				return;
			} else if (inputList.get(a).getValue(actualIndex) == 0) {
				actualValue = 0;
				return;
			}
		}
		actualValue = 1;
	}

	public Integer compute(Integer input1, Integer input2) {
		this.outputValue = new Integer(0);

		if (input1 == 1 && input2 == 1)
			this.outputValue = (Integer) 1;

		return this.outputValue;
	}

	// //////////////////////////////////////////////

	public void draw(final Graphics g) {
		int y1 = y + 40;
		g.drawLine(x + 10, y, x + 10, y1);
		g.drawArc(x - 20, y, 60, 40, -90, 180);
	}

}
